package cn.chenxiejia;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

/***
 * @program: maven
 * @ClassName: Data1
 * @Description: 序列化及反序列化
 * @Author: chenxiejia
 * @Date: 2022/1/20 10:16
 * @version : V1.0
 */
public class Objectsteam {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        User u1 = new User(1, 18, "陈卸甲1");
//        User u2 = new User(2, 18, "陈卸甲2");
//        User u3 = new User(3, 18, "陈卸甲3");
//        User u4 = new User(4, 18, "陈卸甲4");
//        User u5 = new User(5, 18, "陈卸甲5");
//        List<User> list = new ArrayList<>();
//        list.add(u1);
//        list.add(u2);
//        list.add(u3);
//        list.add(u4);
//        list.add(u5);
//        System.out.println(list);
//
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("a.dat"));
//        oos.writeObject(list);
//        oos.flush();
//        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("a.dat"));

        List<User> list1 = new ArrayList<>();
        list1 = (List<User>) ois.readObject();
        System.out.println(list1);
        ois.close();
    }
}
